package top.hekun.study;

import com.jd.platform.async.callback.ICallback;
import com.jd.platform.async.callback.IWorker;
import com.jd.platform.async.worker.WorkResult;
import com.jd.platform.async.wrapper.WorkerWrapper;
import lombok.SneakyThrows;

import java.util.Map;

public class WorkerDemo implements IWorker<Integer, String>, ICallback<Integer, String> {
    private String name;

    public WorkerDemo(String name) {
        this.name = name;
    }

    @SneakyThrows
    @Override
    public String action(Integer param, Map<String, WorkerWrapper> allWrappers) {
        System.out.println(name + " : " + "开始执行");
        Thread.sleep(param);
        System.out.println(name + " : " + "执行完");
        return name + " : " + "延时调用返回";
    }

    @Override
    public String defaultValue() {
        System.out.println(name + " : " + "超时");
        return name + " : 默认返回";
    }

    @Override
    public void begin() {
        System.out.println(name + " : " + "开始");
    }

    @Override
    public void result(boolean success, Integer param, WorkResult<String> workResult) {
        System.out.println(name + " : " + "回调");
    }
}
